package com.example.bobo.yuejian322.Adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.bobo.yuejian322.Fragment.ViewHolder.ZhuYe_PlayVierHolder;
import com.example.bobo.yuejian322.R;
import com.example.bobo.yuejian322.bean.Contest;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List;


public class ZhuyePlayAdapter extends RecyclerView.Adapter    {


    private List<Contest> contestList = new ArrayList<>();
    private Context context;//上下文对象
    private LayoutInflater layoutInflater;

    //构造函数
    public ZhuyePlayAdapter(Context context, List<Contest> contestList ){


        this.context=context;//保存上下文
        layoutInflater=LayoutInflater.from(context);
        this.contestList.addAll(contestList);//显示数据

    }




    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View itemView = layoutInflater.inflate(R.layout.item_zhuye_play,parent,false);

        ZhuYe_PlayVierHolder holder=new ZhuYe_PlayVierHolder(itemView);

        return holder;
    }
    //绑定数据
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        ZhuYe_PlayVierHolder zhuYe_playVierHolder = (ZhuYe_PlayVierHolder) holder;
        Contest contest  = contestList.get(position);


        //获取具体的数据值


        String Intro = contest.getName();
        String pic = contest.getThumb();


        zhuYe_playVierHolder.play_intro.setText(Intro);



        if (pic != "") {
            Picasso.with(context).load("http://172.24.10.175/workout/Uploads/"+pic).
                    into(zhuYe_playVierHolder.play_image);
        }


        //页面跳转
        zhuYe_playVierHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
 //启动新的Activity—店铺详情（菜谱列表）。

              /*  Intent intent = new Intent(context, FoodListActivity.class);
                //传值
                intent.putExtra("phonenum", phone);
                intent.putExtra("shop_id", shopId);
                intent.putExtra("shop_name", shopName);
                //在适配器里调用StarActivity方法
                context.startActivity(intent);*/


            }
        });

    }

    //显示条目的数量
    @Override
    public int getItemCount() {
        return contestList.size();
    }


}
